import { defineConfig } from 'vite'
import {resolve} from "path"
import vue from '@vitejs/plugin-vue'
import Unocss from 'unocss/vite'
import dts from "vite-plugin-dts";
// import { visualizer } from "rollup-plugin-visualizer";
import { libInjectCss } from 'vite-plugin-lib-inject-css';
// https://vitejs.dev/config/
//

export default defineConfig({
  optimizeDeps: {
    include: ['@kangc/v-md-editor/lib/theme/vuepress.js'],
  },
  plugins: [
    vue(),
    Unocss(),
    dts(),
    // visualizer({ open: true, emitFile: true, filename: "stats.html" }),
    libInjectCss(),
  ],
  build:{
    // minify:false, // 混淆和压缩选项
    lib:{
      entry:resolve(__dirname, 'index.ts'),
      name: "index",
      fileName:"index",
      // fileName: (format) => `index.${format}.js`,
      formats: ["es"]
    },
    rollupOptions: {
      // make sure to externalize deps that shouldn't be bundled
      // into your library
      external: ['vue'],
      output: {
        // Provide global variables to use in the UMD build
        // for externalized deps
        globals: {
          vue: 'Vue',
        },
      },
    },
    // rollupOptions: {
    //   // makeAbsoluteExternalsRelative:false,
    //   external: ["vue", "vue-router","pina"],
      
    //   output: {
    //     dir: "dist/dist-ui",
    //     hoistTransitiveImports:false,
    //     // preserveModules:true,
    //     // preserveModulesRoot:"libs",
    //     exports: "named",
    //     chunkFileNames: 'chunks/[name].[hash].js',
    //     entryFileNames:(t) => {
    //       return t.name == 'index' ? '[name].js' : 'libs/[name]/index.[hash].js'
    //     },
    //     // chunkFileNames: (ckinfo) => {
    //     //   console.log(ckinfo)
    //     //   return `${ckinfo.name}-${ckinfo.type}.js`
    //     // },
    //     assetFileNames:'[ext]/[name]-[hash][extname]',
    //     manualChunks: id => {
    //       // 将 node_modules 中的代码单独打包成一个 JS 文件
    //       if(id.includes('node_modules')) {
    //         return 'vendor'
    //       }
    //     },
    //     // assetFileNames: (ckinfo) => {
    //     //   console.log(ckinfo)
    //     //   return 'assets/index.css'
    //     // },
    //     globals: {
    //       vue: "Vue",
    //       "vue-router": "VueRouter",
    //     },
    //   },
    // },
  }
})
